package com.boang.exception;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/*
  @author: 13813
  @date: 2024/7/29 11:02
*/
@ControllerAdvice
public class GlobalExceptionHandle {

    @ExceptionHandler(NullPointerException.class)
    public ModelAndView handleException1() {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("msg", "系统异常，请稍后再试");
        modelAndView.setViewName("error");
        return modelAndView;
    }

    @ExceptionHandler(ArithmeticException.class)
    @ResponseBody
    public String handleException2() {
        return "系统异常，请稍后再试";
    }
}
